package edu.uclmgmu.bacteriosec.domain.data;

import java.io.File;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;

import edu.uclmgmu.bacteriosec.aspects.common.FilesStore;
import edu.uclmgmu.bacteriosec.domain.FiltroGenerico;

public class AspectFamily {
	private String name;
	private Hashtable<String, MethodCatched> methodsCatched;
	private Vector<CallResult> callResults;

	public AspectFamily(String name) {
		this.name=name;
		this.methodsCatched=new Hashtable<String, MethodCatched>();
		this.callResults=new Vector<CallResult>();
	}

	public String getName() {
		return this.name;
	}

	public void addMethodCatched(String methodCatched) {
		MethodCatched m=this.methodsCatched.get(methodCatched);
		if (m==null) {
			m=new MethodCatched(methodCatched);
			this.methodsCatched.put(methodCatched, m);
		}
	}

	public void addTestCase(String methodCatchedName, String testCaseFullName) throws IOException {
		MethodCatched m=this.methodsCatched.get(methodCatchedName);
		m.add(testCaseFullName);
	}
	
	public Enumeration<MethodCatched> getMethodsCatched() {
		return this.methodsCatched.elements();
	}

	public void removeMethodCatched(String methodCatched) {
		this.methodsCatched.remove(methodCatched);
		FilesStore.cleanTempPath(methodCatched);
	}

	public int getNumberOfCalls() {
		int result=0;
		Enumeration<MethodCatched> mmcc=this.methodsCatched.elements();
		while (mmcc.hasMoreElements()) {
			MethodCatched mc=mmcc.nextElement();
			result+=mc.getNumberOfCalls();
		}
		return result;
	}

	public void loadTestCaseNames(Vector<String> testCaseNames) {
		Enumeration<MethodCatched> mmcc=this.methodsCatched.elements();
		while (mmcc.hasMoreElements()) {
			MethodCatched mc=mmcc.nextElement();
			mc.loadTestCaseNames(testCaseNames);
		}
	}

	public MethodCatched get(String methodCatched) {
		return this.methodsCatched.get(methodCatched);
	}
	
	@Override
	public String toString() {
		return this.name;
	}

	public Vector<TestCaseExecuted> getTestCases() {
		Vector<TestCaseExecuted> result=new Vector<TestCaseExecuted>();
		Enumeration<MethodCatched> mmcc=this.methodsCatched.elements();
		while (mmcc.hasMoreElements()) {
			MethodCatched mc=mmcc.nextElement();
			mc.loadTestCases(result);
		}
		return result;
	}

	public void addCallResult(CallResult cr) {
		this.callResults.add(cr);
	}

	public Vector<CallResult> getCallResults() {
		return callResults;
	}
}
